package com.quyou.funtour.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quyou.funtour.dao.UserDao;
import com.quyou.funtour.dao.UserParticipateActivityDao;
import com.quyou.funtour.po.UserParticipateActivityPo;
import com.quyou.funtour.service.UserParticipateActivityService;
import com.quyou.funtour.service.UserService;
import com.quyou.funtour.vo.UserParticipateActivityVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserParticipateActivityServiceImpl
        extends ServiceImpl<UserParticipateActivityDao, UserParticipateActivityPo>
        implements UserParticipateActivityService {

    @Autowired
    private UserService userService;

    /**
     * 根据活动id获取参与活动的用户
     * @param aid
     * @return
     */
    @Override
    public List<UserParticipateActivityVo> getList(String aid) {
        List<UserParticipateActivityPo> a_id = list(new QueryWrapper<UserParticipateActivityPo>().eq("a_id", aid));
        List<UserParticipateActivityVo> list = new ArrayList<>();
        for (UserParticipateActivityPo userParticipateActivityPo : a_id) {
            UserParticipateActivityVo userParticipateActivityVo = new UserParticipateActivityVo();
            BeanUtils.copyProperties(userParticipateActivityPo,userParticipateActivityVo);
            userParticipateActivityVo.setHeadPic(userService.getById(userParticipateActivityPo.getUid()).getHeadPic());
            list.add(userParticipateActivityVo);
        }
        return list;
    }
}
